<%@ page import="java.net.URLDecoder" %><%--
  Created by IntelliJ IDEA.
  User: Jcdz
  Date: 2019/9/30
  Time: 20:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>知医治</title>
    <link rel="Shortcut Icon" href="<%=request.getContextPath()%>/imgs/Kat-icon.png">
    <!-- 引入bootstrap框架的样式文件 -->
    <link rel="stylesheet" href="<%=request.getContextPath()%>/plugins/bootstrap/css/bootstrap.css" type="text/css">
    <link type="text/css" href="<%=request.getContextPath()%>/css/login.css" rel="stylesheet" />
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/alert.css">
</head>

<body>

<%
    //获取cookie
    //每次请求的时候,会将所有的cookie全部发送给server
    Cookie[] cookies = request.getCookies();

    String uname="";
    String pwd="";
    //定义一个标记位
    boolean flag = false;

    if(null!=cookies && cookies.length>0){
        for(Cookie c:cookies){
            //找到name=username的cookie
            if("uLogin".equals(c.getName())){
                String value = c.getValue();

                if(value.trim().length()==0){
                    break;
                }
                // System.out.println(value.split(":")[0]);

                //如果对用户名进行二级编码,那么此处需要进行二级解码
                uname = value.split(":")[0];

                uname = URLDecoder.decode(URLDecoder.decode(uname,"utf-8"),"utf-8");

                pwd = value.split(":")[1];

                flag = true;
                break;
            }
        }
    }

    pageContext.setAttribute("uname",uname);
    pageContext.setAttribute("pwd",pwd);
    pageContext.setAttribute("flag",flag);


%>

<div class="mt-tabpage" js-tab="3">
    <div class="mt-tabpage-title">
        <a href="javascript:;" class="mt-tabpage-item mt-tabpage-item-cur point">手机登录</a>
        <a href="javascript:;" class="mt-tabpage-item">密码登录</a>
        <a href="javascript:;" class="mt-tabpage-item">立即注册</a>
    </div>
    <div class="mt-tabpage-count">
        <ul class="mt-tabpage-cont__wrap">
            <li class="mt-tabpage-item">
                <div class="container">
                    <div class="row">
                        <div class="col-md-8" id="rightline">
                            <div class="glyphicon glyphicon-phone" style="color: cadetblue;">&nbsp;</div>
                            <input class="inp1" type="text" name="username" placeholder="请输入手机号码" id="phoneLogin"/><br>
                            <div class="glyphicon glyphicon-comment" style="color: cadetblue;">&nbsp;</div>
                            <input class="inp2" type="text" name="username" placeholder="请输入验证码" id="phoneCode">
                            <button type="button" class="btn btn-success"
                                    style="height: 40px; margin-top:-3px;" id="btn">获取验证码</button>
                            <!-- <button type="button" class="btn btn-success" style="height: 40px; margin-top:-3px;">重新获取</button> -->
                            <!-- <button type="button" class="btn btn-success" style="height: 40px; margin-top:-3px; background-color: rgb(179, 172, 171); border: 0px;">60s后重发</button> -->
                            <br>
                            <small>登录即代表同意<button class="alert-api-button alert-btn5"
                                                  style="border: 0px;background-color: white;outline: none;">《知医治相关协议》</button></small>
                            <br>
                            <small>《法律声明及隐私权政策》</small><br>
                            <button type="button" class="btn btn-success bt1" id="submit">登&nbsp;&nbsp;录</button>
                            <small class="glyphicon glyphicon-copyright-mark"
                                   style="padding-top: 40px; padding-left: 170px;">知医治--版权所有2019</small>
                        </div>
                        <div class="col-md-4">
                            <img src="<%=request.getContextPath()%>/imgs/activelogo.png" alt="图片加载失败">
                            <h5><a href="<%=request.getContextPath()%>/index/into"><b>进入首页<b
                                    class="glyphicon glyphicon-menu-right"></b></b></a></h5>
                            <h2>知医治</h2>
                            <small
                                    style="font-family: yingwei;padding-left: 10px; color:rgb(201, 199, 199);">--身体不适&nbsp;需要治一治</small><br>
                        </div><br>
                    </div>
                </div>

            </li>
            <li class="mt-tabpage-item">
                <div class="container">
                    <div class="row">
                        <form action="/treatment/clogin" method="post">
                        <div class="col-md-8 " id="rightline">
                            <div class="glyphicon glyphicon-user" style="color: cadetblue;">&nbsp;</div>
                            <input class="inp1" type="text" name="username" placeholder="请输入手机号码/账号" value="${uname}"><br>

                            <c:if test="${param.error==0}">
                                <div style="padding-top: 0px;">
                                    <span>用户不存在!</span>
                                </div>
                            </c:if>

                            <div class="glyphicon glyphicon-lock" style="color: cadetblue;">&nbsp;</div>
                            <input class="inp1" type="password" name="password" placeholder="请输入密码" value="${pwd}">
                            <br>

                            <c:if test="${param.error==1}">
                                <div style="padding-top: 0px;">
                                    <span>密码错误!</span>
                                </div>
                            </c:if>

                            <c:if test="${flag}">
                                <input class="inp5" type="checkbox" name="flag" checked/> <span
                                    style="font-size: 13px;color:rgb(201, 199, 199);">记住密码</span>
                            </c:if>

                            <c:if test="${!flag}">
                                <input class="inp5" type="checkbox" name="flag" /> <span
                                    style="font-size: 13px;color:rgb(201, 199, 199);">记住密码</span>
                            </c:if>

                            <br>
                            <small>登录即代表同意<button class="alert-api-button alert-btn5"
                                                  style="border: 0px;background-color: white;outline: none;">《知医治相关协议》</button></small>
                            <br>
                            <small>《法律声明及隐私权政策》</small><br>

                            <button type="submit" class="btn btn-success bt1">登&nbsp;&nbsp;录</button>
                            <small class="glyphicon glyphicon-copyright-mark"
                                   style="padding-top: 40px; padding-left: 170px;">知医治--版权所有2019</small>
                        </div>
                        </form>

                        <div class="col-md-4">
                            <img src="<%=request.getContextPath()%>/imgs/activelogo.png" alt="图片加载失败">
                            <h5><a href="<%=request.getContextPath()%>/index/into"><b>进入首页<b
                                    class="glyphicon glyphicon-menu-right"></b></b></a></h5>
                            <h2>知医治</h2>
                            <small
                                    style="font-family: yingwei;padding-left: 10px; color:rgb(201, 199, 199);">--身体不适&nbsp;需要治一治</small><br>

                        </div>
                    </div>
                </div>
            </li>
            <li class="mt-tabpage-item">
                <div class="container">
                    <div class="row">
                        <div class="col-md-8 " id="rightline">
                            <div class="glyphicon glyphicon-phone" style="color: cadetblue;">&nbsp;</div>
                            <input class="inp1" ty-+ pe="text" name="username" placeholder="请输入手机号码" id="phone"><br>
                            <div class="glyphicon glyphicon-comment" style="color: cadetblue;">&nbsp;</div>
                            <input class="inp4" type="text" name="username" placeholder="请输入验证码" id="codeLine">
                            <button type="button" class="btn btn-success"
                                    style="height: 40px; margin-top:-3px;" id="codes">获取验证码</button>
                            <!-- <button type="button" class="btn btn-success" style="height: 40px; margin-top:-3px;">重新获取</button> -->
                            <!-- <button type="button" class="btn btn-success" style="height: 40px; margin-top:-3px; background-color: rgb(179, 172, 171); border: 0px;">60s后重发</button> -->
                            <br>
                            <div class="glyphicon glyphicon-lock" style="color: cadetblue;">&nbsp;</div>
                            <input class="inp1" type="text" name="username" placeholder="请设置您的密码" id="password"><br>
                            <input class="inp5" type="checkbox" name="check-box" id="cks"/> <span
                                style="font-size: 13px;color:rgb(201, 199, 199);">勾选即代表同意<button
                                class="alert-api-button alert-btn5"
                                style="border: 0px;background-color: white;outline: none;">《知医治相关协议》</button></span><br>
                            <input class="inp5" type="checkbox" name="check-box" /> <span
                                style="font-size: 13px;color:rgb(201, 199, 199);" id="cksLogin">注册后登录</span>
                            <button type="button" class="btn btn-success bt1" id="register">注&nbsp;&nbsp;册</button>
                            <small class="glyphicon glyphicon-copyright-mark"
                                   style="padding-top: 0px; padding-left: 170px;">知医治--版权所有2019</small>
                        </div>
                        <div class="col-md-4">
                            <img src="<%=request.getContextPath()%>/imgs/activelogo.png" alt="图片加载失败">
                            <h5><a href="<%=request.getContextPath()%>/index/into"><b>进入首页<b
                                    class="glyphicon glyphicon-menu-right"></b></b></a></h5>
                            <h2>知医治</h2>
                            <small
                                    style="font-family: yingwei;padding-left: 10px; color:rgb(201, 199, 199);">--身体不适&nbsp;需要治一治</small><br>

                        </div>
                    </div>
                </div>
            </li>
        </ul>
    </div>
</div>


<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times</button>
            </div>
            <div class="modal-body">
                <div role="form" action="" method="post">
                    <div class="form-group">
                        <input type="text" class="form-control" placeholder="请输入您的手机号" id="newPhone">
                        <br>
                            <input type="text" class="form-control" placeholder="输入验证码" name="code" style="width: 50%; " id="newCode">
                            <button type="button" class="btn btn-success" id="newBtn">获取验证码</button>
                        <br>
                        <input type="text" class="form-control" placeholder="重新设置您的新密码" id="newPwd">
                        <br>
                        <button type="button" class="btn btn-success" id="btnClick">确认提交</button>
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button class="btn btn-primary" >确定</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<%--//模态框添加结束--%>


<script type="text/javascript">
    var wait=60;
    function time(o) {
        if (wait == 0) {
            o.removeAttribute("disabled");
            o.value="重新获取验证码";
            wait = 60;
        } else {

            o.setAttribute("disabled", true);
            o.value="重新发送(" + wait + ")";
            wait--;
            setTimeout(function() {
                    time(o)
                },
                1000)
        }
    }
    document.getElementById("codes").onclick=function(){time(this);}
</script>
<script type="text/javascript">
    var wait=60;
    function time(o) {
        if (wait == 0) {
            o.removeAttribute("disabled");
            o.value="重新获取验证码";
            wait = 60;
        } else {

            o.setAttribute("disabled", true);
            o.value="重新发送(" + wait + ")";
            wait--;
            setTimeout(function() {
                    time(o)
                },
                1000)
        }
    }
    document.getElementById("newBtn").onclick=function(){time(this);}
</script>
<script type="text/javascript">
    var wait=60;
    function time(o) {
        if (wait == 0) {
            o.removeAttribute("disabled");
            o.value="重新获取验证码";
            wait = 60;
        } else {

            o.setAttribute("disabled", true);
            o.value="重新发送(" + wait + ")";
            wait--;
            setTimeout(function() {
                    time(o)
                },
                1000)
        }
    }
    document.getElementById("btn").onclick=function(){time(this);}
</script>
<!-- bootstrap中的js插件依赖于jquery框架,所以必须先引入jquery的js文件 -->
<script src="<%=request.getContextPath()%>/plugins/jquery/jquery.min.js"></script>
<!--引入bootstrap的js文件-->
<script src="<%=request.getContextPath()%>/plugins/bootstrap/js/bootstrap.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/mt-tabpage.js"></script>
<!-- 引入alert的js文件 -->
<script src="<%=request.getContextPath()%>/js/alert.js"></script>
<script type="text/javascript">
    $(function () {
        $('[js-tab=3]').tab({
            curDisplay: 2,//当前第一个打开
            changeMethod: 'horizontal'//切换选项：默认default，horizontal，vertical，opacity这4种方式
        });

    });
</script>
<script>
    var M = {}
    $(document).delegate(".alert-btn5", 'click', function () {
        if (M.dialog5) {
            return M.dialog5.show();
        }
        M.dialog5 = jqueryAlert({
            'content': alertContent,
            'modal': true,
            'contentTextAlign': 'left',
            'width': '450px',
            'animateType': 'linear',
            'buttons': {
                '不同意': function () {
                    M.dialog5.close();
                },
                '同意': function () {
                    if (M.dialog51) {
                        return M.dialog51.show();
                    }
                    M.dialog5.close();
                    // window.location.href='index.html'
                }
            }
        })
    })
    var alertContent = '<div class="protocol">\
	   <h4 align="center" style="margin-top:0px;">知医治--用户协议</h4>\
	   <p>\
	    </p><h4>一、总则</h4>\
	    &nbsp;&nbsp;1.1  知医治的所有权和运营权归知医治科技有限公司所有。 <br>\
	    &nbsp;&nbsp;1.2  用户在注册之前，应当仔细阅读本协议，并同意遵守本协议后方可成为注册用户。一旦注册成功，则用户与知医治之间自动形成协议关系，用户应当受本协议的约束。用户在使用特殊的服务或产品时，应当同意接受相关协议后方能使用。  <br>\
	    &nbsp;&nbsp;1.3 本协议则可由知医治随时更新，用户应当及时关注并同意本站不承担通知义务。本站的通知、公告、声明或其它类似内容是本协议的一部分。  \
	   <p></p>\
	   <p>\
	   </p><h4>二、服务内容</h4>\
	   &nbsp;&nbsp;2.1 知医治的具体内容由本站根据实际情况提供。 <br>\
       &nbsp;&nbsp;2.2 本站仅提供相关的网络服务，除此之外与相关网络服务有关的设备(如个人电脑、手机、及其他与接入互联网或移动网有关的装置)及所需的费用均应由用户自行负担。\
      </div>'
</script>
<script>
    <%--phone codeline codes password cks cksLogin register--%>
    $(function () {

        $("#codes").click(function () {
            var phone = document.getElementById("phone").value;
            if(phone!=null) {
                $.ajax({
                    url: "sendMsg",
                    data: {phone: phone},
                    type: "POST",
                    success: function (results) {
                        console.log(results)
                        if(results.msg == "该用户已存在，请选择登录"){
                            alert("用户已存在，请登录");
                            return
                        }
                    }
                })
            }else {
                alert("请输入手机号")
            }
        })

            $("#register").click(function () {
                if($("#cks").prop("checked")) {
                    var phone = document.getElementById("phone").value;
                    var codeLine = document.getElementById("codeLine").value;
                    var password = document.getElementById("password").value;

                    var mobilereg1 = /^1[3|5|6|7|8|9][0-9]{9}$/;
                    var mobilereg2 = /^14[5|7][0-9]{8}$/;
                    var r=/^[1-9][0-9]+$/gi;
                    if(!phone){
                        alert("请输入手机号码")
                        return;
                    }else if(!mobilereg1.test(phone)&&!mobilereg2.test(phone)){
                        alert("手机号输入不合法请重新输入")
                        return;
                    }else if(!r.test(codeLine)&&codeLine.length!=6){
                        alert("验证码输入格式不正确")
                        return;
                    }else if (password == null && password == ""){
                        alert("密码不能为空")
                        return;
                    }else{

                        $.ajax({
                            url:"register",
                            data:{phone:phone,codeLine:codeLine,password:password},
                            type:"POST",
                            success:function (result) {

                                console.log(result)

                                if(result.message != codeLine){
                                    alert("验证码输入不正确，请确认")
                                    return;
                                }else{
                                    alert("注册成功请返回登录")
                                    window.location.reload();
                                }

                            }
                        })


                    }


                    console.log(phone)
                    console.log(codeLine)
                    console.log(password)
                }else{
                    alert("请先确认读取相关协议")
                }
            })



    })
</script>

<script>
    $(function () {

        $("#btn").click(function () {

            var phoneLogin = document.getElementById("phoneLogin").value;
            if(phoneLogin!=null) {
                $.ajax({
                    url: "sendMsgLogin",
                    data: {phoneLogin: phoneLogin},
                    type: "POST",
                    success: function (result) {
                        console.log(result)
                    }
                })
            }else {
                alert("请输入手机号")
            }

        })

        $("#submit").click(function () {

            var phoneLogin = document.getElementById("phoneLogin").value;
            var phoneCode = document.getElementById("phoneCode").value;
            var mobile1 = /^1[3|5|6|7|8|9][0-9]{9}$/;
            var mobile2 = /^14[5|7][0-9]{8}$/;

            if(!phoneLogin){
                alert("请输入手机号")
                return;
            }else if(!mobile1.test(phoneLogin)&&!mobile2.test(phoneLogin)){
                alert("手机号格式不正确")
                return;
            }else if(phoneCode.length!=6){
                alert("验证码格式不正确");
                return;
            }else {
                $.ajax({
                    url:"phoneLogin",
                    data:{phoneLogin:phoneLogin,phoneCode:phoneCode},
                    type:"POST",
                    success:function (result) {

                        console.log(result)
                        if (result.message == "用户不存在请您注册"){
                            alert("用户不存在请您注册")
                            window.location.reload()
                        }

                        if(result.message == "登陆成功"){
                            window.location="dept";
                        }

                    }
                })
            }

        })

    })

</script>

<script>

    <%--newPhone newCode newBtn newPwd newRwd rSub--%>

    $("#newBtn").click(function () {
        var newPhone = document.getElementById("newPhone").value;
        console.log(newPhone)
        $.ajax({
            url:"/treatment/forgetCode",
            data:{newPhone:newPhone},
            success:function (result) {
                console.log(result)
//                if(result.message = "该用户不存请您注册"){
//                    alert("该手机号不存在，请确认再次输入")
//                    return;
//                }
            }
        })

    $("#btnClick").click(function () {

        var newPhone = document.getElementById("newPhone").value;
        var newCode = document.getElementById("newCode").value;
        var newPwd = document.getElementById("newPwd").value;
            $.ajax({

                url:"/treatment/udpPwd",
                data:{newPhone:newPhone,newCode:newCode,newPwd:newPwd},
                type:"POST",
                success:function (result) {

                    if (result.message == "密码更改成功请返回登录"){
                        alert("密码更改成功请返回登录")
                        window.location.reload()
                    }

                }
            })


    })

})

</script>
</body>
</html>
